<div class="problemindexholder" problemindex="A">
 <div class="ttypography">
  <div class="problem-statement">
   <div class="header">
    <div class="title">
     A. Pride
    </div>
    <div class="time-limit">
     <div class="property-title">
      time limit per test
     </div>
     2 seconds
    </div>
    <div class="memory-limit">
     <div class="property-title">
      memory limit per test
     </div>
     256 megabytes
    </div>
    <div class="input-file">
     <div class="property-title">
      input
     </div>
     standard input
    </div>
    <div class="output-file">
     <div class="property-title">
      output
     </div>
     standard output
    </div>
   </div>
   <div>
    <p>
     You have an array
     <span class="tex-span">
      <i>
       a
      </i>
     </span>
     with length
     <span class="tex-span">
      <i>
       n
      </i>
     </span>
     , you can perform operations. Each operation is like this: choose two
     <span class="tex-font-style-bf">
      adjacent
     </span>
     elements from
     <span class="tex-span">
      <i>
       a
      </i>
     </span>
     , say
     <span class="tex-span">
      <i>
       x
      </i>
     </span>
     and
     <span class="tex-span">
      <i>
       y
      </i>
     </span>
     , and replace one of them with
     <span class="tex-span">
      <i>
       gcd
      </i>
      (
      <i>
       x
      </i>
      ,
      <i>
       y
      </i>
      )
     </span>
     , where
     <span class="tex-span">
      <i>
       gcd
      </i>
     </span>
     denotes the
     <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">
      greatest common divisor
     </a>
     .
    </p>
    <p>
     What is the minimum number of operations you need to make all of the elements equal to
     <span class="tex-span">
      1
     </span>
     ?
    </p>
   </div>
   <div class="input-specification">
    <div class="section-title">
     Input
    </div>
    <p>
     The first line of the input contains one integer
     <span class="tex-span">
      <i>
       n
      </i>
     </span>
     (
     <span class="tex-span">
      1 ≤
      <i>
       n
      </i>
      ≤ 2000
     </span>
     ) — the number of elements in the array.
    </p>
    <p>
     The second line contains
     <span class="tex-span">
      <i>
       n
      </i>
     </span>
     space separated integers
     <span class="tex-span">
      <i>
       a
      </i>
      <sub class="lower-index">
       1
      </sub>
      ,
      <i>
       a
      </i>
      <sub class="lower-index">
       2
      </sub>
      , ...,
      <i>
       a
      </i>
      <sub class="lower-index">
       <i>
        n
       </i>
      </sub>
     </span>
     (
     <span class="tex-span">
      1 ≤
      <i>
       a
      </i>
      <sub class="lower-index">
       <i>
        i
       </i>
      </sub>
      ≤ 10
      <sup class="upper-index">
       9
      </sup>
     </span>
     ) — the elements of the array.
    </p>
   </div>
   <div class="output-specification">
    <div class="section-title">
     Output
    </div>
    <p>
     Print
     <span class="tex-font-style-tt">
      -1
     </span>
     , if it is impossible to turn all numbers to
     <span class="tex-span">
      1
     </span>
     . Otherwise, print the minimum number of operations needed to make all numbers equal to
     <span class="tex-span">
      1
     </span>
     .
    </p>
   </div>
   <div class="sample-tests">
    <div class="section-title">
     Examples
    </div>
    <div class="sample-test">
     <div class="input">
      <div class="title">
       Input
      </div>
      <pre>5<br/>2 2 3 4 6<br/></pre>
     </div>
     <div class="output">
      <div class="title">
       Output
      </div>
      <pre>5<br/></pre>
     </div>
     <div class="input">
      <div class="title">
       Input
      </div>
      <pre>4<br/>2 4 6 8<br/></pre>
     </div>
     <div class="output">
      <div class="title">
       Output
      </div>
      <pre>-1<br/></pre>
     </div>
     <div class="input">
      <div class="title">
       Input
      </div>
      <pre>3<br/>2 6 9<br/></pre>
     </div>
     <div class="output">
      <div class="title">
       Output
      </div>
      <pre>4<br/></pre>
     </div>
    </div>
   </div>
   <div class="note">
    <div class="section-title">
     Note
    </div>
    <p>
     In the first sample you can turn all numbers to
     <span class="tex-span">
      1
     </span>
     using the following
     <span class="tex-span">
      5
     </span>
     moves:
    </p>
    <ul>
     <li>
      <span class="tex-span">
       [2, 2, 3, 4, 6]
      </span>
      .
     </li>
     <li>
      <span class="tex-span">
       [2, 1, 3, 4, 6]
      </span>
     </li>
     <li>
      <span class="tex-span">
       [2, 1, 3, 1, 6]
      </span>
     </li>
     <li>
      <span class="tex-span">
       [2, 1, 1, 1, 6]
      </span>
     </li>
     <li>
      <span class="tex-span">
       [1, 1, 1, 1, 6]
      </span>
     </li>
     <li>
      <span class="tex-span">
       [1, 1, 1, 1, 1]
      </span>
     </li>
    </ul>
    <p>
     We can prove that in this case it is not possible to make all numbers one using less than
     <span class="tex-span">
      5
     </span>
     moves.
    </p>
   </div>
  </div>
  <p>
  </p>
 </div>
</div>
